package org.example.system.controller.sysuser;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.common.core.constants.HttpConstants;
import org.example.common.core.controller.BaseController;
import org.example.common.core.model.Result;
import org.example.common.core.model.vo.LoginUserVO;
import org.example.system.model.sysuser.dto.LoginDTO;
import org.example.system.model.sysuser.dto.SysUserSaveDTO;
import org.example.system.model.sysuser.vo.SysUserVO;
import org.example.system.service.sysuser.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : [Pashm]
 * @version : [v1.0]
 */
@RestController
@RequestMapping("/sysuser")
@Tag(name = "管理员接口")
public class SysUserController extends BaseController {

     @Autowired
     private ISysUserService sysUserService;
    //返回值：登录成功或失败    int code 1成功   0失败
    // 失败的原因             String

    @PostMapping("/login")
    @Operation(summary = "管理员登录", description = "根据账号密码进行管理员登录")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public Result<String> login(@RequestBody LoginDTO loginDTO){
          return sysUserService.login(loginDTO.getUserAccount(),loginDTO.getPassword());
    }
    //接口地址: /system/sysuser/info
    @GetMapping("/info")
    @Operation(summary = "返回用户信息", description = "返回现在登录用户的信息")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙请稍后重试")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
         return sysUserService.info(token);
    }
    //管理员的增删查改

    @PostMapping("/add")
    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public Result<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO){
         return toResult(sysUserService.add(sysUserSaveDTO));
    }

    @DeleteMapping("/{userId}")
    @Operation(summary = "删除用户", description = "通过用户id删除用户")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "用户Id")
    })
    @ApiResponse(responseCode = "1000", description = "成功删除用户")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后再试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")
    public Result<Void> delete(@PathVariable Long userId){
        return null;
    }

    @GetMapping("/detail")
    @Operation(summary = "用户详情", description = "根据查询条件查询用户详情")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "用户Id"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "用户性别")
    })
    @ApiResponse(responseCode = "1000", description = "成功获取用户信息")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户不存在")
    public Result<SysUserVO> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex){
        return null;
    }

    @DeleteMapping("/logout")
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toResult(sysUserService.logout(token));
    }
}
